<template>
  <div>
    <el-container>
      <el-header>
        <div>后台管理系统</div>
        <el-menu
          :default-active="activeIndex"
          class="el-menu-demo"
          mode="horizontal"
          background-color="#545c64"
          @select="selectMenu"
        >
          <el-menu-item :index="index" v-for="(item, index) in menus" :key="index">{{
            item.name
          }}</el-menu-item>
          <el-submenu index="2">
            <template slot="title">我的工作台</template>
            <el-menu-item @click="logout">退出</el-menu-item>
            <el-menu-item index="2-4-2">修改</el-menu-item>
          </el-submenu>
        </el-menu>
      </el-header>
      <el-container>
        <el-aside :width="isCollapse ? '64px' : '200px'">
          <div class="leftMenu" @click="leftCollapse">|||</div>
          <el-menu
            default-active="2"
            class="el-menu-vertical-demo"
            background-color="#545c64"
            text-color="#fff"
            active-text-color="#ffd04b"
            router
            :collapse="isCollapse"
            :collapse-transition="false"
          >
            <el-menu-item :index="item.url" v-for="(item, index) in subMenu" :key="index">
              <i class="el-icon-menu"></i>
              <span slot="title">{{ item.name }}</span>
            </el-menu-item>
          </el-menu>
        </el-aside>

        <el-main>
           <bread />
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import bread from './bread'
import nav from "@/utils/navMenu";
export default {
  props: [],
  components: {
      
      bread
  },
  data() {
    return {
      isCollapse: false,
      activeIndex: "1",
      menus: [], //一级菜单
      subMenu: [], //二级菜单
    };
  },
  created() {
    console.log(nav);
    this.menus = nav; //把一级菜单进行赋值
    this.subMenu = this.menus[0].children;
  },
  mounted() {},
  methods: {
    leftCollapse() {
      this.isCollapse = !this.isCollapse;
    },
    handleSelect(key, keyPath) {
      console.log(key, keyPath);
    },
    logout() {
      
        this.$store.commit("logout");
        this.$message.success("退出成功");
        this.$router.push("/login");

      
    },

    selectMenu(index) {
      console.log(index);
      console.log(this.subMenu);
      this.subMenu = this.menus[index].children;

    },
  },
  computed: {},
  watch: {},
};
</script>

<style scoped>
.el-container {
  width: 100%;
}
.el-header {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #545c64;
}
.el-header > div {
  font-size: 20px;
  color: #fff;
}
.el-aside {
  height: 700px;
  background: #545c64;
}
.leftMenu {
  width: 100%;
  height: 30px;
  text-align: center;
  line-height: 30px;
  background: rgb(101, 100, 100);
  font-size: 16px;
  cursor: pointer;
  color: #fff;
}
.el-tag {
  margin-right: 10px;
}
</style>
